package com.ecoolex.hotel.saas.platform.graphql;

import org.apache.dubbo.config.annotation.Reference;
import org.springframework.lang.NonNull;

import com.ecoolex.framework.modularize.api.auth.annotation.PlatformAuthoritativeRegister;
import com.ecoolex.framework.modularize.api.auth.platform.PlatformMemberAuthority;
import com.ecoolex.framework.web.api.graphql2.annotation.GraphQL2Module;
import com.ecoolex.framework.web.api.graphql2.annotation.QueryField;
import com.ecoolex.framework.web.api.graphql2.annotation.GraphQL2Module.Type;
import com.ecoolex.framework.web.api.graphql2.annotation.MutationField;
import com.ecoolex.hotel.saas.entity.StoreOrderConfig;
import com.ecoolex.hotel.saas.platform.core.PlatformConstant;
import com.ecoolex.hotel.saas.pojo.EditStoreOrderConfigDTO;
import com.ecoolex.hotel.saas.ws.StoreService;

@GraphQL2Module(type = Type.Platform, description = "商户订单处理配置")
@PlatformAuthoritativeRegister(parentKey = PlatformConstant.AUTH_PROJECT_KEY,
	key = StoreOrderConfigGraphql.AUTH,
	name = "商户订单处理配置",
	remark = "商户订单处理配置")
public class StoreOrderConfigGraphql {

	public static final String AUTH = PlatformConstant.AUTH_PROJECT_KEY + "-STORE-ORDER-CONFIG";
	
	private static final String AUTH_GET = AUTH + "-GET";
	
	private static final String AUTH_EDIT = AUTH + "-EDIT";
	
	@Reference
	private StoreService storeService;
	
	@QueryField(field = "storeOrderConfig", description = { "商户订单处理配置" })
	@PlatformAuthoritativeRegister(parentKey = AUTH, key = AUTH_GET, name = "商户订单处理配置")
	public StoreOrderConfig get(@NonNull Integer storeId, PlatformMemberAuthority user) {
		user.assertAuth(AUTH_GET);
		return storeService.getStoreOrderConfig(storeId);
	}
	
	@MutationField(field = "editStoreOrderConfig", description = "编辑商户订单处理配置")
	@PlatformAuthoritativeRegister(parentKey = AUTH, key = AUTH_EDIT, name = "商户订单处理配置")
	public StoreOrderConfig edit(@NonNull EditStoreOrderConfigDTO edit, PlatformMemberAuthority user) {
		user.assertAuth(AUTH_EDIT);
		return storeService.editStoreOrderConfig(edit, user.userName());
	}
	
}
